import { Component, InjectionToken, OnInit } from '@angular/core';
import { AppService } from './services/app.service';
import { ContentHeaderService } from './services/content-header.service';
import { LoginInfoService } from './services/login-info.service';
import { UserInfoDto } from './models/sys/user-info.dto';
import { timer } from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less']
})
export class AppComponent implements OnInit {
  title = 'sso-client1'
  isLoggedIn = false;
  user?: UserInfoDto;

  contentHeader = '';
  constructor(private _appService: AppService,
    private _contentHeader: ContentHeaderService,
    private _loginInfo: LoginInfoService) { }

  ngOnInit(): void {
    this.isLoggedIn = this._appService.checkCredentials();

    this._contentHeader.header.subscribe((value) => {
      this.contentHeader = value;
    });

    // Refresh token every 1 hour
    timer(3600 * 1000).subscribe((val) => {
      console.log(`refresh count ${val}`);

      this._appService.refreshToken();
    });
  }
}

export const REST_URL = new InjectionToken("rest_url");
export const REST_ADDR = new InjectionToken("rest_addr");
export const REDIRECT_ADDR = new InjectionToken("redirect_addr");